package com.itxx.thread3;

public class ThreadDemo implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if(Thread.currentThread().getName().equals("曹操")&&i==20){
                try {
                    System.out.println("------曹操遇见张飞休息------");
                    Thread.sleep(10);
                    System.out.println("------曹操醒了------");
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }
            }else if (Thread.currentThread().getName().equals("曹操")&&i==50){
                try {
                    System.out.println("------曹操遇见关羽休息------");
                    Thread.sleep(20);
                    System.out.println("------曹操醒了------");
                } catch (InterruptedException e) {
                    e.printStackTrace();

                }
            }

            System.out.println(Thread.currentThread().getName() + "已经跑了:" + i + "公里");
        }
    }
}

class Test {
    public static void main(String[] args) {
        ThreadDemo t = new ThreadDemo();
        Thread c = new Thread(t, "曹操");
        Thread l = new Thread(t, "刘备");
        Thread s = new Thread(t, "孙权");
        //修改曹操的优先级为6
        c.setPriority(10);
        //修改刘备的优先级为4
        s.setPriority(1);
        c.start();
        l.start();
        s.start();
    }
}
